package cn.qyd.javathread;

import java.util.Arrays;

/**
 * @author 邱运铎
 * @date 2024-03-14 16:16
 */
public class ThreadGroupDemo {
    public static void main(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("I am thread");
            }
        };

        Thread thread = new Thread(runnable);
        System.out.println("the new thread name is :" + thread.getName() +" and group name is : " + thread.getThreadGroup().getName());
        System.out.println("the main thread name is :" + Thread.currentThread().getName() +" and group name is : " + Thread.currentThread().getThreadGroup().getName());

        ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
        Thread[] threads = new Thread[threadGroup.activeCount()];
        threadGroup.enumerate(threads);
        System.out.println(Arrays.toString(threads));
    }
}
